knitr::opts_chunk$set(warning = F,message = F)
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(lubridate))
library(autoTS)
Le chargement a nécessité le package : prophet
Le chargement a nécessité le package : Rcpp
Le chargement a nécessité le package : rlang
The autoTS package provides a high level interface for univariate time series predictions. It implements many algorithms, most of them provided by the forecast package. The main goals of the package are :
The package is designed to work on one time series at a time. Parallel calculations can be put on top of it (see example below). The user has to provide 2 simple vectors :
lubridate package can parse them)This package implements each algorithm with a unique parametrization, meaning that the user cannot tweak the algorithms (eg modify SARIMA specfic parameters).
For this example, we will use the GDP quarterly data of the european countries provided by eurostat. The database can be downloaded from this page and then chose “GDP and main components (output, expenditure and income) (namq_10_gdp)” and then adjust the time dimension to select all available data and download as a csv file with the correct formatting (1 234.56). The csv is in the “Data” folder of this notebook.
dat <- read.csv("Data/namq_10_gdp_1_Data.csv")
str(dat)
'data.frame': 93456 obs. of 7 variables:
$ TIME : Factor w/ 177 levels "1975Q1","1975Q2",..: 1 1 1 1 1 1 1 1 1 1 ...
$ GEO : Factor w/ 44 levels "Albania","Austria",..: 15 15 15 15 15 15 15 15 15 15 ...
$ UNIT : Factor w/ 3 levels "Chain linked volumes (2010), million euro",..: 2 2 2 2 3 3 3 3 1 1 ...
$ S_ADJ : Factor w/ 4 levels "Calendar adjusted data, not seasonally adjusted data",..: 4 2 1 3 4 2 1 3 4 2 ...
$ NA_ITEM : Factor w/ 1 level "Gross domestic product at market prices": 1 1 1 1 1 1 1 1 1 1 ...
$ Value : Factor w/ 19709 levels ":","1 008.3",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Flag.and.Footnotes: Factor w/ 5 levels "","b","c","e",..: 1 1 1 1 1 1 1 1 1 1 ...
head(dat)
First, we have to clean the data (not too ugly though). First thing is to convert the TIME column into a well known date format that lubridate can handle. In this example, the yq function can parse the date without modification of the column. Then, we have to remove the blank in the values that separates thousands… Finally, we only keep data since 2000 and the unadjusted series in current prices.
After that, we should get one time series per country
dat <- mutate(dat,dates=yq(as.character(TIME)),
values = as.numeric(stringr::str_remove(Value," "))) %>%
filter(year(dates)>=2000 & S_ADJ=="Unadjusted data (i.e. neither seasonally adjusted nor calendar adjusted data)" &
UNIT == "Current prices, million euro")
NAs introduits lors de la conversion automatique
filter(dat,GEO %in% c("France","Austria")) %>%
ggplot(aes(dates,values,color=GEO)) + geom_line() + theme_light() +
labs(title="GDP of (completely) random countries")
Now we’re good to go !
Let’s see how to use the package on one time series :
ex1 <- filter(dat,GEO=="France")
preparedTS <- prepare.ts(ex1$dates,ex1$values,"quarter")
## What is in this new object ?
str(preparedTS)
List of 4
$ obj.ts : Time-Series [1:77] from 2000 to 2019: 363007 369185 362905 383489 380714 ...
$ obj.df :'data.frame': 77 obs. of 2 variables:
..$ dates: Date[1:77], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ val : num [1:77] 363007 369185 362905 383489 380714 ...
$ freq.num : num 4
$ freq.alpha: chr "quarter"
plot.ts(preparedTS$obj.ts)
ggplot(preparedTS$obj.df,aes(dates,val)) + geom_line() + theme_light()
## What is the best model for prediction ?
best.algo <- getBestModel(ex1$dates,ex1$values,"quarter",bagged = T,graph = F)
Registered S3 method overwritten by 'xts':
method from
as.zoo.xts zoo
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Registered S3 methods overwritten by 'forecast':
method from
fitted.fracdiff fracdiff
residuals.fracdiff fracdiff
names(best.algo)
[1] "best" "graph.train" "res.train"
print(paste("The best algorithm is",best.algo$best))
[1] "The best algorithm is my.prophet"
plotly::ggplotly(best.algo$graph.train)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
## Build the predictions
final.pred <- my.predictions(preparedTS,best.algo$best)
tail(final.pred,24)
ggplot(final.pred) + geom_line(aes(dates,actual.value),color="black") +
geom_line(aes(dates,prophet,linetype=type),color="red") +
theme_light()
Not too bad, right ?
Let’s say we want to make a prediction for each country in the same time and be the fastest possible \(\rightarrow\) let’s combine the package’s functions with parallel computing. We have to reshape the data to get one column per country and then iterate over the columns of the data frame.
suppressPackageStartupMessages(library(tidyr))
dat.wide <- select(dat,GEO,dates,values) %>%
group_by(dates) %>%
spread(key = "GEO",value = "values")
head(dat.wide)
library(doParallel)
Le chargement a nécessité le package : foreach
Le chargement a nécessité le package : iterators
Le chargement a nécessité le package : parallel
pipeline <- function(dates,values)
{
bm <- getBestModel(dates,values,"quarter",graph = F)
pred <- prepare.ts(dates,values,"quarter") %>%
my.predictions(bm$best)
return(pred)
}
doMC::registerDoMC(parallel::detectCores()-1) # parallel backend (for UNIX)
system.time({
res <- foreach(ii=2:ncol(dat.wide),.packages = c("dplyr","autoTS")) %dopar%
pipeline(dat.wide$dates,pull(dat.wide,ii))
})
utilisateur système écoulé
512.473 2.167 104.269
names(res) <- colnames(dat.wide)[-1]
str(res)
List of 44
$ Albania :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ stlm : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ Austria :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 50422 53180 53881 56123 52911 ...
$ Belgium :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 62261 65046 62754 68161 64318 ...
$ Bosnia and Herzegovina :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ stlm : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ Bulgaria :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 2941 3252 4015 4103 3284 ...
$ Croatia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ tbats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 5266 5811 6409 6113 5777 ...
$ Cyprus :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 2547 2784 2737 2738 2688 ...
$ Czechia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 15027 16430 17229 18191 16677 ...
$ Denmark :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 42567 44307 43892 47249 44143 ...
$ Estonia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 1391 1575 1543 1662 1570 ...
$ Euro area (12 countries) :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ Euro area (19 countries) :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ Euro area (EA11-2000, EA12-2006, EA13-2007, EA15-2008, EA16-2010, EA17-2013, EA18-2014, EA19):Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ European Union - 15 countries (1995-2004) :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ European Union - 27 countries (from 2019) :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ European Union - 28 countries :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ Finland :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 31759 33836 34025 36641 34474 ...
$ France :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 363007 369185 362905 383489 380714 ...
$ Germany (until 1990 former territory of the FRG) :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 515500 523900 536120 540960 530610 ...
$ Greece :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ ets : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 33199 34676 37285 37751 35237 ...
$ Hungary :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 11516 12630 13194 13955 12832 ...
$ Iceland :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 2304 2442 2557 2447 2232 ...
$ Ireland :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 25583 26751 27381 28666 29766 ...
$ Italy :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 292517 309098 298655 338996 309967 ...
$ Kosovo (under United Nations Security Council Resolution 1244/99) :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ stlm : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
$ Latvia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 1848 2165 2238 2382 2005 ...
$ Lithuania :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ stlm : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 2657 3124 3267 3505 2996 ...
$ Luxembourg :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 5646 5730 5689 6015 5811 ...
$ Malta :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 979 1110 1158 1152 1031 ...
$ Montenegro :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 0 0 0 0 0 ...
..$ bagged : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
$ Netherlands :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 109154 113124 110955 118774 118182 ...
$ North Macedonia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 901 1052 1033 1108 986 ...
$ Norway :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 44900 43730 46652 50638 48355 ...
$ Poland :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 41340 44210 46944 54163 47445 ...
$ Portugal :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 30644 31923 32111 33788 31927 ...
$ Romania :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 7901 9511 11197 11630 8530 ...
$ Serbia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 0 0 0 0 0 ...
$ Slovakia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ sarima : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 5100 5722 5764 5752 5343 ...
$ Slovenia :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ tbats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 5147 5591 5504 5667 5407 ...
$ Spain :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 153378 162400 158526 171946 166204 ...
$ Sweden :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ stlm : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 67022 73563 68305 73399 66401 ...
$ Switzerland :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ bats : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 70048 72725 74957 77476 76092 ...
$ Turkey :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ actual.value: num [1:89] 59944 70803 82262 82981 60075 ...
..$ bagged : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
$ United Kingdom :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 4 variables:
..$ dates : Date[1:89], format: "2000-01-01" "2000-04-01" "2000-07-01" "2000-10-01" ...
..$ type : chr [1:89] NA NA NA NA ...
..$ prophet : num [1:89] NA NA NA NA NA NA NA NA NA NA ...
..$ actual.value: num [1:89] 438090 440675 446918 462127 441157 ...
There is no best algorithm in general \(\Rightarrow\) depends on the data !
sapply(res,function(xx) colnames(select(xx,-dates,-type,-actual.value)) ) %>% table()
.
bagged bats ets prophet sarima stlm tbats
2 8 1 14 12 5 2
sapply(res,function(xx) colnames(select(xx,-dates,-type,-actual.value)) )
Albania
"stlm"
Austria
"prophet"
Belgium
"prophet"
Bosnia and Herzegovina
"stlm"
Bulgaria
"sarima"
Croatia
"tbats"
Cyprus
"sarima"
Czechia
"sarima"
Denmark
"prophet"
Estonia
"sarima"
Euro area (12 countries)
"bats"
Euro area (19 countries)
"bats"
Euro area (EA11-2000, EA12-2006, EA13-2007, EA15-2008, EA16-2010, EA17-2013, EA18-2014, EA19)
"bats"
European Union - 15 countries (1995-2004)
"bats"
European Union - 27 countries (from 2019)
"bats"
European Union - 28 countries
"bats"
Finland
"sarima"
France
"prophet"
Germany (until 1990 former territory of the FRG)
"prophet"
Greece
"ets"
Hungary
"prophet"
Iceland
"bats"
Ireland
"sarima"
Italy
"prophet"
Kosovo (under United Nations Security Council Resolution 1244/99)
"stlm"
Latvia
"sarima"
Lithuania
"stlm"
Luxembourg
"sarima"
Malta
"prophet"
Montenegro
"bagged"
Netherlands
"sarima"
North Macedonia
"sarima"
Norway
"prophet"
Poland
"prophet"
Portugal
"prophet"
Romania
"sarima"
Serbia
"prophet"
Slovakia
"sarima"
Slovenia
"tbats"
Spain
"prophet"
Sweden
"stlm"
Switzerland
"bats"
Turkey
"bagged"
United Kingdom
"prophet"